﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Web.Mvc;
using Kendo.Mvc;
using Kendo.Mvc.Infrastructure;
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using SecurityApi.DataAccess;

namespace SecurityAdmin.Web.Controllers
{
    public class UserController : BaseController
    {
        //
        // GET: /User/

        public ActionResult GetUsers()
        {
            return View();
        }

        public ActionResult GetEnterpriseUsers()
        {
            return View();
        }


        public ActionResult CreateNewUser()
        {
            return View();
        }

        public ActionResult AjaxGetAllUsers([DataSourceRequest] DataSourceRequest request)
        {
            SecurityApi.DataAccess.EnterpriseUserRepository repository = new SecurityApi.DataAccess.EnterpriseUserRepository();
            IQueryable<SecurityApi.Model.EnterpriseUser> users = repository.GetAll();
            return Json(users.ToDataSourceResult(request));
        }

        public ActionResult AjaxGetEnterpriseUsers([DataSourceRequest] DataSourceRequest request,int enterpriseId)
        {
            SecurityApi.DataAccess.EnterpriseUserRepository repository = new SecurityApi.DataAccess.EnterpriseUserRepository();
            IQueryable<SecurityApi.Model.EnterpriseUser> users = repository.GetAll().Where(e=>e.EnterpriseId==enterpriseId);
            return Json(users.ToDataSourceResult(request));
        }

        public ActionResult AjaxGetApplicationUsers([DataSourceRequest] DataSourceRequest request,int appId)
        {
            SecurityApi.DataAccess.EnterpriseUserRepository repository = new SecurityApi.DataAccess.EnterpriseUserRepository();
            IQueryable<SecurityApi.Model.EnterpriseUser> users = repository.GetApplicationUsers(appId);
            return Json(users.ToDataSourceResult(request));
        }

        public ActionResult SelectUser(int userId)
        {
            SecurityApi.DataAccess.EnterpriseUserRepository repository = new SecurityApi.DataAccess.EnterpriseUserRepository();
            EnterpriseUser user = repository.GetUserById(userId);
            SelectedUser = user;
            return RedirectToAction("RoleManager", "UserRole");
        }

    }
}
